import axios from 'axios';

export async function translateMyMemory (
  text: string,
  sourceLang = 'en',
  targetLang = 'zh',
) {
  try {
    const res = await axios.get('https://api.mymemory.translated.net/get', {
      params: {
        q: text,
        langpair: `${sourceLang}|${targetLang}`,
      },
    });
    return res.data.responseData.translatedText;
  } catch (error) {
    if (error instanceof Error) {
      console.error('Translation failed:', error.message);
    }
    return text; // 失败时返回原文
  }
}
